<HTML><HEAD><TITLE>print(?Term)</TITLE>
</HEAD><BODY>[ <A HREF="index.html">Term I/O</A> | <A HREF="../../index.html">Reference Manual</A> | <A HREF="../../fullindex.html">Alphabetic Index</A> ]
<H1>print(?Term)</H1>
The term Term is written on the output stream according to the current
operator declarations, using the predicate portray/2 or portray/1 if it
exists.


<DL>
<DT><EM>Term</EM></DT>
<DD>Prolog term.
</DD>
</DL>
<H2>Description</H2>
   Used to print the term Term on the current output according to the
   current operator declarations, i.e.  the same as write/1, however the
   user has the possibility to influence the way the term is printed.  If
   the predicate portray/2 is visible in the module where print/1 was
   called from, it is used by print/1 in the following way:

<P>
  * If Term is a variable, it is printed using write/1.

<P>
  * If Term is a nonvariable or an attributed variable, then portray(output,
    Term) is called.  If it succeeds, so does print/1.  Otherwise, if Term is
    atomic, it is written using write/1 and the predicate succeeds.  If
    Term is a compound term, its main functor is printed using write/1 and
    print/1 is called recursively on its arguments.

<P>
   If portray/2 is not visible but portray/1 is, it is called instead of
   portray/2.

<P>
   Note that when this predicate is used to print a list, only the elements
   of the list, i.e.  the heads, are passed to the recursive calls of
   print/1, but not the list tails.

<P>
   portray/1, 2 is used by the system when printing out the answer binding
   in the top-level loop to the answer_output stream and in the debugger,
   when the output command is set to print, to the debug_output stream.

<P>
   As usual, the output is buffered, so it may need to be flushed (e.g.
   explicitly using flush/1).

<P>
Note
   The output of print/1 is not necessarily in a form acceptable to
   read/1,2.

<P>

<H3>Modes and Determinism</H3><UL>
<LI>print(?) is det
</UL>
<H3>Modules</H3>
This predicate is sensitive to its module context (tool predicate, see @/2).
<H2>Examples</H2>
<PRE>
Success:
    [eclipse]: [user].
     portray(S, a) :- write(S, b).
     user   compiled 100 bytes in 0.02 seconds

    yes.
    [eclipse]: print([a, b, c, d]).
    [b, b, c, d]
    yes.
    [eclipse]: [user].
     portray(S, '$VAR'(X)) :- write(S, a_), write(S, X).
     user   compiled 180 bytes in 0.00 seconds

    yes.
    [eclipse]: quintus.
    loading the library /usr/local/ECLIPSE/lib/quintus.pl
    loading the library /usr/local/ECLIPSE/lib/cprolog.pl
    loading the library /usr/local/ECLIPSE/lib/cio.pl

    yes.
    [eclipse]: numbervars(f(A, B, A, C), 1, X),
            write(f(A, B, A, C)).
    f($VAR(1), $VAR(2), $VAR(1), $VAR(3))
    B = a_2        % print/2 is used in the top-level loop
    A = a_1
    C = a_3
    X = 4
    yes.




</PRE>
<H2>See Also</H2>
<A HREF="../../kernel/ioterm/display-1.html">display / 1</A>, <A HREF="../../kernel/ioterm/display-2.html">display / 2</A>, <A HREF="../../kernel/ioterm/print-2.html">print / 2</A>, <A HREF="../../kernel/ioterm/write-1.html">write / 1</A>, <A HREF="../../kernel/ioterm/write-2.html">write / 2</A>, <A HREF="../../kernel/ioterm/writeq-1.html">writeq / 1</A>, <A HREF="../../kernel/ioterm/writeq-2.html">writeq / 2</A>
</BODY></HTML>
